package com.eightbears.beboy.ui.chat;

import com.eightbears.beboy.base.util.CommonAPI;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMCmdMessageBody;
import com.hyphenate.chat.EMMessage;

/**
 * Created by Bao on 2017/6/28.
 */
public class ChatUtil {

    public static void sendCMSMessage(String action, String groupId, String userId) {
        EMMessage cmdMsg = EMMessage.createSendMessage(EMMessage.Type.CMD);
        cmdMsg.setChatType(EMMessage.ChatType.GroupChat);
        EMCmdMessageBody cmdBody = new EMCmdMessageBody(action);
        cmdMsg.setFrom(userId);
        cmdMsg.setTo(groupId);
        cmdMsg.setAttribute(CommonAPI.PARAMS_USER_ID, userId);
        cmdMsg.setAttribute(CommonAPI.PARAMS_GROUP_ID, groupId);
        cmdMsg.addBody(cmdBody);
        EMClient.getInstance().chatManager().sendMessage(cmdMsg);
    }

    public static void sendCMSMessage(String action, String paramsTitle, String params, String groupId, String userId) {
        EMMessage cmdMsg = EMMessage.createSendMessage(EMMessage.Type.CMD);
        cmdMsg.setChatType(EMMessage.ChatType.GroupChat);
        EMCmdMessageBody cmdBody = new EMCmdMessageBody(action);
        cmdMsg.setFrom(userId);
        cmdMsg.setTo(groupId);
        cmdMsg.setAttribute(CommonAPI.PARAMS_GROUP_ID, groupId);
        cmdMsg.setAttribute(paramsTitle, params);
        cmdMsg.addBody(cmdBody);
        EMClient.getInstance().chatManager().sendMessage(cmdMsg);
    }
}
